package com.onjob.message;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.onjob.employment.Resume;
import com.onjob.recruit.Company;
import com.onjob.recruit.CompanyDao;
import com.onjob.recruit.Recruit;
import com.onjob.security.Users;
import com.opensymphony.xwork2.ActionSupport;

public class ResumeRecruitAction extends ActionSupport {
	private static final long serialVersionUID = 1L;
	private ResumeRecruitDao resumeRecruitDao;
	private CompanyDao companyDao;
	private String recruitId;
	private String resumeId;
	private ResumeRecruit resumeRecruit;
	private String id;
	private List<ResumeRecruit> results;
	
	

	public List<ResumeRecruit> getResults() {
		return results;
	}

	public void setResults(List<ResumeRecruit> results) {
		this.results = results;
	}

	public CompanyDao getCompanyDao() {
		return companyDao;
	}

	public void setCompanyDao(CompanyDao companyDao) {
		this.companyDao = companyDao;
	}

	public ResumeRecruit getResumeRecruit() {
		return resumeRecruit;
	}

	public void setResumeRecruit(ResumeRecruit resumeRecruit) {
		this.resumeRecruit = resumeRecruit;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public ResumeRecruitDao getResumeRecruitDao() {
		return resumeRecruitDao;
	}

	public void setResumeRecruitDao(ResumeRecruitDao resumeRecruitDao) {
		this.resumeRecruitDao = resumeRecruitDao;
	}

	public String getRecruitId() {
		return recruitId;
	}

	public void setRecruitId(String recruitId) {
		this.recruitId = recruitId;
	}

	public String getResumeId() {
		return resumeId;
	}

	public void setResumeId(String resumeId) {
		this.resumeId = resumeId;
	}

	public String execute() {

		return SUCCESS;
	}

	public String addResumeToRecruit() {
		ResumeRecruit resumeRecruit = new ResumeRecruit();
		Resume resume = new Resume();
		resume.setId(resumeId);
		Recruit recruit = new Recruit();
		recruit.setId(recruitId);
		resumeRecruit.setRecruitId(recruit);
		resumeRecruit.setResumeId(resume);
		this.resumeRecruitDao.saveOrUpdate(resumeRecruit);
		return SUCCESS;
	}

	public String setUserReadTag() {
		this.resumeRecruitDao.setUserReadTag(id);
		return SUCCESS;
	}
	public String setCompanyReadTag() {
		this.resumeRecruitDao.setCompanyReadTag(id);
		return SUCCESS;
	}

	public String delete() {
		this.resumeRecruitDao.delete(resumeRecruit);
		return SUCCESS;
	}

	public String selectMessageByCompany() {

		HttpServletRequest servletRequest = ServletActionContext.getRequest();
		Users user = (Users) servletRequest.getSession().getAttribute("user");
		Company company = companyDao.getCompanyByUser(user);
		this.resumeRecruitDao.getResumeByCompany(company.getId());
		return SUCCESS;
	}

	public String selectMessageByUser() {
		HttpServletRequest servletRequest = ServletActionContext.getRequest();
		Users user = (Users) servletRequest.getSession().getAttribute("user");
		this.resumeRecruitDao.getResumeByUser(user.getId().toString());
		return SUCCESS;
	}

}
